package mailService

import (
	"fmt"
	"gitee.com/yangguoliang001/go-gin-vue3/QO"
	"gitee.com/yangguoliang001/go-gin-vue3/config"
	"gitee.com/yangguoliang001/go-gin-vue3/pkg/mail"
	"gitee.com/yangguoliang001/go-gin-vue3/pkg/response"
	"gitee.com/yangguoliang001/go-gin-vue3/util/code"
	"github.com/gin-gonic/gin"
	"github.com/spf13/cast"
)

func (m *mailService) SendEmailService(c *gin.Context, mailReq QO.EmailReqQO) error {

	o := &mail.Options{
		MailHost: mailReq.Host,
		MailPort: cast.ToInt(mailReq.Port),
		MailUser: mailReq.User,
		MailPass: mailReq.Pass, // wxpghvpfsptuecah
		MailTo:   mailReq.To,
		Subject:  fmt.Sprintf("%s[%s] 邮箱告警人调整通知", config.ProjectName, "dev"),
		Body:     fmt.Sprintf("%s[%s] 已添加您为系统告警通知人", config.ProjectName, "dev"),
	}
	err := mail.Send(o)
	fmt.Println("err", err, o)
	if err != nil {
		response.Fail(c, code.SendEmailError, code.Text(code.SendEmailError), gin.H{"realErr": err})
		return err
	}
	return nil
}
